#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Node 
{
    char ch;
    struct Node* prev;
    struct Node* next;
} Node;

int main()
{
    int n, k;
    scanf_s("%d %d", &n, &k);
    char s[200005];
    scanf_s("%s", s);

    Node* head = NULL;
    Node* tail = NULL;
    Node* cur = NULL;
    Node* prev_node = NULL;

    for (int i = 0; i < n; i++) 
    {
        Node* new_node = (Node*)malloc(sizeof(Node));
        new_node->ch = s[i];
        new_node->prev = prev_node;
        new_node->next = NULL;
        if (prev_node != NULL)
        {
            prev_node->next = new_node;
        }
        else
        {
            head = new_node;
        }
        prev_node = new_node;
        if (s[i] == 'I')
        {
            cur = new_node;
        }
        tail = new_node;
    }

    char op[10];
    for (int i = 0; i < k; i++) 
    {
        scanf_s("%s", op);
        if (strcmp(op, "backspace") == 0)
        {
            if (cur->prev != NULL && cur->next != NULL && cur->prev->ch == '(' && cur->next->ch == ')') 
            {
                Node* left = cur->prev;
                Node* right = cur->next;

                if (left->prev != NULL)
                {
                    left->prev->next = cur;
                }
                else 
                {
                    head = cur;
                }
                cur->prev = left->prev;

                if (right->next != NULL) 
                {
                    right->next->prev = cur;
                }
                else
                {
                    tail = cur;
                }
                cur->next = right->next;

                free(left);
                free(right);
            }
            else if (cur->prev != NULL) 
            {
                Node* prev = cur->prev;
                if (prev->prev != NULL)
                {
                    prev->prev->next = cur;
                }
                else 
                {
                    head = cur;
                }
                cur->prev = prev->prev;
                free(prev);
            }
        }
        else if (strcmp(op, "delete") == 0) 
        {
            if (cur->next != NULL) 
            {
                Node* next = cur->next;
                cur->next = next->next;
                if (next->next != NULL)
                {
                    next->next->prev = cur;
                }
                else 
                {
                    tail = cur;
                }
                free(next);
            }
        }
    }

    Node* current = head;
    while (current != NULL)
    {
        printf("%c", current->ch);
        current = current->next;
    }
    printf("\n");

    current = head;
    while (current != NULL) 
    {
        Node* temp = current;
        current = current->next;
        free(temp);
    }

    return 0;
}